home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10398 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: ix.netcom.com!netnews
  2. From: miker3@ix.netcom.com (Mike Rubenstein)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: fflush and Visual C++
  5. Date: Sun, 17 Mar 1996 16:14:23 GMT
  6. Organization: Netcom
  7. Message-ID: <314c38f1.145222809@nntp.ix.netcom.com>
  8. References: <4idhv5$dnv@news.mhv.net> <314b173b.71056173@nntp.ix.netcom.com> <4ig0cq$gkg@skivs.ski.org>
  9. NNTP-Posting-Host: ix-dc12-26.ix.netcom.com
  10. X-NETCOM-Date: Sun Mar 17  8:14:23 AM PST 1996
  11. X-Newsreader: Forte Agent .99d/32.182
  12.  
  13. gt@ns.oon.or.jp (Gemini Thunder) wrote:
  14.  
  15. > miker3@ix.netcom.com (Mike Rubenstein) wrote:
  16. > >Vinny.Bedus@bbs.mhv.net (Vinny Bedus) wrote:
  17. > >> Can someone please tell me why when fflush function is used in Visual C 
  18. > >> under a dos box it doesn't work?  I have no problems with turbo c for win 
  19. > >> but anything else and it doesn't flush the stdin buffer.
  20. > >>  any ans??????????????
  21. > >Perhaps because Visual C implements fflush() correctly.  fflush() does
  22. > >not flush input buffers.  fflush() with stdin as an argument results
  23. > >in undefined behavior.
  24. > >Michael M Rubenstein
  25. > Could you explain why fflush(stdin) results in undefined behavior?
  26. > I have been using this construct, (apparently) unaware of this.
  27.  
  28. Because the standard does not define what fflush(stdin) does.  From
  29. ISO 7.9.5.2:
  30.  
  31.     If stream points to an output stream or an update stream in     
  32.     which the most recent operation was not input, the fflush 
  33.     function causes any unwritten data for that stream to be 
  34.     delivered to the host environment to be written to the file; 
  35.     otherwise, the behavior is undefined.
  36.  
  37. I'd suggest you stick to using fflush() for its intended purpose --
  38. flushing output streams.
  39.  
  40.  
  41.  
  42. Michael M Rubenstein
  43.